Series

Series

对应一维数组的数据结构,可以保存任何类型的数据

Series的创建

# 导入pandas
import pandas as pd

pd.Series(data=None, index=None, dtype=None)

通过已有数据创建

>>> pd.Series(np.arange(9))

0    0
1    1
2    2
3    3
4    4
5    5
6    6
7    7
8    8
dtype: int32
>>> pd.Series([1.2, 2.3, 4.5, 5.0], index=[1, 2, 3, 4])

1    1.2
2    2.3
3    4.5
4    5.0
dtype: float64

通过字典数据创建

>>> color_count = pd.Series({'red':10, 'green':20, 'blue':100})
>>> color_count

red       10
green     20
blue     100
dtype: int64

Series的属性

>>> color_count.index

Index(['red', 'green', 'blue'], dtype='object')

>>> color_count.values
array([ 10,  20, 100], dtype=int64)

>>> color_count[0]
10